<%@ page import="org.biojava.dasobert.dasregistry.*"%>
<jsp:directive.page	import="org.biojava.dasobert.dasregistry.DasSourceComparator" />
<jsp:directive.page import="org.biojava.dasobert.dasregistry.Das1Source" />

<jsp:useBean id="register" class="dasregistry.registryBean"	scope="page" />
<jsp:useBean id="coord"    class="dasregistry.coordBean"    scope="session" />
<jsp:setProperty name="register" property="*" />

<%@ page import="org.biojava.services.das.dao.RegistryUser"%>
<%@ page import="org.biojava.services.das.registry.UserManager"%>
<%@ page import="org.biojava.services.das.dao.Role"%>
<%@ page import="org.biojava.services.das.dao.RegistryUser"%>
<%@ page import="org.biojava.services.das.dao.ProjectBean"%>


<%@ include file="logincheck.jsp"%>


<HTML>
<HEAD>
<title>remove DAS server</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
  <link rel="stylesheet"    type="text/css"     href="stylesheet.css" />
  <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
   <script type="text/javascript" src="dropdown.js" language="javascript" ></script>
</HEAD>

<BODY>


<%
	String title = "remove DAS source";
	String header = title;
%>



<%@ include file="sangerheader.jsp"%>

<div id="main"><%@ include file="sangertablestart.jsp"%>


<%
	// init
	String serverurl = request.getParameter("url");
	String passkey = request.getParameter("passkey");
	DasSource ds = null;
	if ( serverurl != null )
		ds = register.getDasSourceByURL(serverurl);
%>

<h2>Removing <%=serverurl%>
<h2>
<%
	boolean isOwner = false;
	int status = -1;

	if (coord.userOwnsASource(user, new DasSource[] { ds })) {
		isOwner = true;		
	}

	if ( Role.isAdmin(user) ) {
		isOwner = true;
	}
	if ( isOwner ) {
		status = coord.removeService(serverurl, user);
	}
	
	if (!isOwner) {
%>


<p>To remove a server, the key is required that is returned after
registration of the server.</p>
<p>If you forgot your key, you can ask for a <a
	href="reminder.jsp?url=<%=serverurl%>">reminder</a>.</p>

<%
	}

	if (passkey != null) {

		// passkey has been entered

		// out.println(passkey);
		// status can be: 
		// 1: successfully renewed
		// 2:  incorrect key ;
		// 3: some other error occured;

		status = register.removeService(serverurl, passkey);
	}

	if (status == 1) {
		out.println(" successfully removed server ");
	} else if (status == 2) {
%> <b>wrong key!</b> <%
 	passkey = null;

 	} else {
 		out.println("sorry, an unknown error occured");
 	}

 	if ((status != 1) && (passkey == null)) {
 %>


<table border="0">
	<form method="post" action="removeServer.jsp" name="count_form">
	<tr>
		<td colspan="2">enter key for server <%=serverurl%></td>
	</tr>
	<tr>
		<td align="right"><input type="password" name="passkey" value="" /></td>
		<td align="left"><input type="hidden" name="url"
			value="<%=serverurl%>"> <input type="submit" value="remove">
		</td>
	</tr>

	</form>
</table>

<%
}
%> <%@ include file="sangertableend.jsp"%> <%@ include
	file="sangerfooter.jsp"%>